<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Init Model
 *
 */
class Settings_model extends CI_Model {

    var $settings = array();

    /**
     * Get Settings
     *
     * Get all the auto loaded settings from the db.
     *
     * @return	array
     */
//-------Get Settings-----------------------S    
    function get_settings() {
        if (!$this->db->table_exists('web_settings')) {
            return FALSE;
            die();
        }
        $sql = "select variable,value from web_settings where auto = 1";
        $query = $this->db->query($sql);
        foreach ($query->result() as $k => $row) {
            $this->settings[$row->variable] = $row->value;
        }
        return $this->settings;
    }

    /**
     * Get Setting (Notice Singular)
     *
     * Used to pull out one specific setting from the settings table.
     * */
//-------Get A Setting-----------------------S    
    function get_setting($name) {
        if (!empty($this->settings[$name])) {
            return $this->settings[$name];
        } else {
            $this->db->select('value')->from('web_settings')->where('variable', $name);
            $query = $this->db->get();
            if ($query->num_rows() > 0) {
                $row = $query->row();
                return $row->value;
            }
            return FALSE;
        }
    }
//-------Get Settings Detail-----------------------S    
    function settings_detail() {
        $this->db->select('*');
        $query = $this->db->get('web_settings');
        $result = $query->result();
        return $result;
    }

}